package com.ycz.master.controller;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycz.master.pojo.DataFiling;
import com.ycz.master.pojo.User;
import com.ycz.master.pojo.UserAndDatafiling;
import com.ycz.master.service.DataFilingService;
import com.ycz.master.service.UserAndDataFilingService;
import com.ycz.master.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * author zyc
 * Created on 2021/9/28 15:19
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService service;

    @Autowired
    DataFilingService dataservice;

    @Autowired
    UserAndDataFilingService userrvice;

//    @RequestMapping("/findall")
//    @ResponseBody
//    public PageInfo alluser(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
//        //传入页码 每页八条
//        PageHelper.startPage(pn,8);
//
//        List<User> findall = service.findall();
//        //连续显示的页数
//        PageInfo page=new PageInfo(findall,5);
//        return page;
//    }

    @RequestMapping("/findall")
    @ResponseBody
    public PageInfo alluser(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
        //传入页码 每页八条
        PageHelper.startPage(pn,8);

        List<UserAndDatafiling> findall = userrvice.findall();
        //连续显示的页数
        PageInfo page=new PageInfo(findall,5);
        return page;
    }

    @RequestMapping("/bankfindall")
    @ResponseBody
    public PageInfo bankalluser(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
        //传入页码 每页八条
        PageHelper.startPage(pn,8);

        List<UserAndDatafiling> findall = userrvice.bankfindall();
        //连续显示的页数
        PageInfo page=new PageInfo(findall,5);
        return page;
    }



    @RequestMapping("/find")
    @ResponseBody
    public PageInfo allusersss(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
        //传入页码 每页八条
        PageHelper.startPage(pn,8);

        List<UserAndDatafiling> findall = userrvice.findall();
        //连续显示的页数
        PageInfo page=new PageInfo(findall,5);
        return page;
    }

    @RequestMapping("/selectid/{id}")
    @ResponseBody
    public User find(@PathVariable("id") Integer id){
        return service.fingbyid(id);
    }

    @RequestMapping("/selectdataid/{id}")
    @ResponseBody
    public DataFiling finddata(@PathVariable("id") Integer id){

        return dataservice.findbyid(id);
    }

    @RequestMapping("/updata")
    @ResponseBody
    public Boolean get(@RequestParam("check")String id,
                       @RequestParam("dfId") String dfid,
                         String commentA){
        Boolean updata = dataservice.updata(dfid, id,commentA);

//        System.out.println(id);
        return updata;
    }

    @RequestMapping("/bankupdata")
    @ResponseBody
    public Boolean bankget(@RequestParam("check")String id,
                           @RequestParam("dfId") String dfid,
                           @RequestParam("result")Integer result,
                           String commentB){
        Boolean updata = dataservice.bankupdata(dfid, id,result,commentB);

//        System.out.println(id);
        return updata;
    }



    @RequestMapping("/search")
    @ResponseBody
    public PageInfo search(@RequestParam(value = "pn",defaultValue = "1")Integer pn,@RequestParam("key")String key){
        //传入页码 每页八条
        PageHelper.startPage(pn,8);

        List<User> users = service.findbyname(key, key);
        //连续显示的页数
        PageInfo page=new PageInfo(users,5);
        return page;
    }
}
